const BaseHandler = require('../base-handler');
const SystemServices = require('../../../constants').SystemServices;
const HTTP_VERBS = require('../../../constants').HTTP_VERBS;
const utils = require('../../../utils');

class RootHandler extends BaseHandler {
    get pattern() {
        return "/";
    }

    doGET(request, response) {
        var session = request.session;
        var security_code = utils.uuid();

        if (session && session.user && session.user.authenticated) {
            response.redirect('/admin/to/dingstore');
        } else {
            request.session.user.security_code = security_code;
            response.render('login', {
                success: true,
                security_code: security_code,
                data: {}
            });
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = RootHandler;